package wh.guistuff;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;

public class MyLogTable extends JTable
{
	private static Color gridColor = new Color(150, 228, 255);
	private static Color rowColor = new Color(248, 248, 255); // Ghost white
	private static Color selrowColor = new Color(230, 230, 250);
	private static Color headerColor = new Color(255, 255, 224);
	private static Font cellFont = new Font("serif", Font.TRUETYPE_FONT, 18);
	
	
	public MyLogTable(DefaultTableModel model) {
		
		super(model);
		initTable();
	}
	

	public void initTable() {
		
		setGridColor(gridColor);
		setRowHeight(20);
		setFont(cellFont);
		// getColumnModel().setColumnMargin(12);
		JTableHeader header = getTableHeader();
		header.setBackground(headerColor);
		header.setPreferredSize(new Dimension(60, 20));
		Dimension tableDim = new Dimension(750, 400);
		setPreferredScrollableViewportSize(tableDim);
	}

	@Override
	public boolean isCellEditable(int rowIndex, int colIndex) {
		return false; // Disallow the editing of any cell
	}

	@Override
	public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
		
		Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
		// even index, selected or not selected
		if (Index_row % 2 == 0) {
			comp.setBackground(rowColor);
		} else {
			comp.setBackground(Color.white);
		}
		
		if ((isCellSelected(Index_row, Index_col) == true)) {
			
			comp.setBackground(selrowColor);
			
		}
		
		return comp;
	}

}
